package cn.zhfeat.hatch.web.service.impl.system;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import cn.zhfeat.core.base.BaseResultModel;
import cn.zhfeat.core.base.ResultStatus;
import cn.zhfeat.core.shiro.ShiroSessionData;
import cn.zhfeat.core.shiro.bean.ShiroSysAuthorityBean;
import cn.zhfeat.hatch.dto.sysuser.*;
import cn.zhfeat.hatch.entity.sysuser.*;
import cn.zhfeat.hatch.rpc.IAccountRpcService;
import cn.zhfeat.hatch.rpc.IRoleRpcService;
import cn.zhfeat.hatch.web.service.IAccountService;
import cn.zhfeat.hatch.web.service.IRoleService;
import cn.zhfeat.hatch.web.utils.ShiroSessionDataUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.google.common.base.FinalizablePhantomReference;

/**
 * @description: 角色信息相关实现层
 *
 *
 * @author ZhangHao
 * @date 2018年5月21日 下午2:27:26
 * @version 1.0.0.1
 */
@Service("roleService")
public class RoleServiceImpl implements IRoleService {

	@Autowired
	private IRoleRpcService roleRpcService;
	@Autowired
	private IAccountRpcService accountRpcService;
	@Autowired
	private IAccountService accountService;

	/**
	 * @description: 角色列表查询
	 *
	 *
	 * @param param
	 * @return
	 * @author ZhangHao
	 * @date 2018年5月21日 下午2:39:01
	 * @version 1.0.0.1
	 */
	@Override
	public Object ajaxPageData(String param) {

		JSONObject paramObj = JSONObject.parseObject(param);
		int startIndex = paramObj.getInteger("start");
		int pageSize = paramObj.getInteger("length");
		int draw = paramObj.getInteger("draw");
		JSONObject obj = paramObj.getJSONObject("extra_search");
		String roleName = "";
		if(obj != null) {
			roleName = obj.getString("roleName");
		}

		//获取用户所绑定的参数
		ShiroSessionData shiroSessionData = ShiroSessionDataUtil.getShiroSessionData();
		SysRoleDto dto = new SysRoleDto();
		dto.setShiroSessionData(shiroSessionData);
		dto.setStartIndex(startIndex);
		dto.setPageSize(pageSize);
		dto.setName(roleName);
		dto.setCid(shiroSessionData.getCid());
		PageInfo<SysRole> pageInfo = roleRpcService.ajaxPageListByDto(dto);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		if(pageInfo != null) {
			resultMap.put("recordsTotal", pageInfo.getTotal());
			resultMap.put("recordsFiltered", pageInfo.getTotal());
			resultMap.put("data", pageInfo.getList());
			resultMap.put("draw", draw);
		}
		return resultMap;
	}

	/**
	 * @description: 角色删除操作
	 *
	 * @param dto
	 * @return
	 * @author ZhangHao
	 * @date 2018年5月21日 下午6:50:08
	 * @version 1.0.0.1
	 */
	@Override
	public Object delete(SysRoleDto dto) {

		BaseResultModel baseResultModel = new BaseResultModel();

		//1、根据角色下的全部用户
		SysUserRoleDto sysUserRoleDto = new SysUserRoleDto();
		sysUserRoleDto.setRoleId(dto.getId());
		List<SysUserRole> sysUserRoles = accountRpcService.selectSysUserRoles(sysUserRoleDto);

		//2、如果该角色下有用户，则不能删除
		if(sysUserRoles!= null && sysUserRoles.size() > 0) {
			// 角色有用户，不能删除
			baseResultModel.setStatus(ResultStatus.HTTP_REQUEST_ERROR.getStatusCode());
			baseResultModel.setMessage("您选中的角色下有用户，不能删除");
			return baseResultModel;
		}
		//3、根据角色id删除角色信息
		SysRole roleEntity = new SysRole();
		roleEntity.setId(dto.getId());
		roleEntity.setIsDeleted(1);
		roleEntity.setUpdateTime(new Date());
		int a = roleRpcService.updateSelective(roleEntity);

		//4、根据角色id删除用户角色信息
		sysUserRoleDto.setUpdateTime(new Date());
		accountRpcService.updateSysUserRolesByType(sysUserRoleDto);

		//5、根据角色id删除角色菜单信息
		SysRoleAuthorityDto sysRoleAuthorityDto =  new SysRoleAuthorityDto();
		sysRoleAuthorityDto.setRoleId(dto.getId());
		sysRoleAuthorityDto.setUpdateTime(new Date());
		roleRpcService.updateSysRoleAuthorityByDto(sysRoleAuthorityDto);

		//6、根据角色id删除角色数据权限信息
		SysRoleAttribute sysRoleAttributeEntity = new SysRoleAttribute();
		sysRoleAttributeEntity.setRoleId(dto.getId());
		sysRoleAttributeEntity.setUpdateTime(new Date());
		roleRpcService.updateSysRoleAttribute(sysRoleAttributeEntity);

		if(a > 0) {
			baseResultModel.setStatus(ResultStatus.SUCCESS.getStatusCode());
			baseResultModel.setMessage(ResultStatus.SUCCESS.getStatusMessage());
			return baseResultModel;
		}else {
			baseResultModel.setStatus(ResultStatus.HTTP_REQUEST_ERROR.getStatusCode());
			baseResultModel.setMessage("删除失败");
			return baseResultModel;
		}
	}

	/**
	 * @description: 从数据库查询该公司最大客户对应的菜单权限
	 *
	 * @param dto
	 * @return
	 * @author ZhangHao
	 * @date 2018年5月22日 下午3:09:00
	 * @version 1.0.0.1
	 */
	@Override
	public Object ajaxAuthorityGroupList(SysRoleDto dto) {

		BaseResultModel baseResultModel = new BaseResultModel();

		//获取用户所绑定的参数
		ShiroSessionData shiroSessionData = ShiroSessionDataUtil.getShiroSessionData();

		//1、查询该公司对应的超级管理员用户
		Long cid = shiroSessionData.getCid();
		SysUserDto sysUserDto = new SysUserDto();
		sysUserDto.setShiroSessionData(shiroSessionData);
		sysUserDto.setCid(cid);
		sysUserDto.setIsSuper(1);
		SysUser sysUser = accountRpcService.findUserInfoByType(sysUserDto);
		//2、查询该用户对应的角色，product_id = 0
		SysUserRoleDto sysUserRoleDto = new SysUserRoleDto();
		sysUserRoleDto.setUserId(sysUser.getId());
		sysUserRoleDto.setProductId(0l);
		List<SysUserRole> list = accountRpcService.selectSysUserRoles(sysUserRoleDto);
		//3、循环角色查询角色对应的全部菜单，包含菜单的详细信息，并进行去重
		List<SysRoleAuthority> sysAuthoritysList =  new ArrayList<SysRoleAuthority>();
		for(int i=0;i<list.size();i++) {
			SysRoleAuthorityDto sysRoleAuthorityDto = new SysRoleAuthorityDto();
			sysRoleAuthorityDto.setRoleId(list.get(i).getRoleId());
			List<SysRoleAuthority> sysAuthoritys = roleRpcService.findSysRoleAuthorityByDto(sysRoleAuthorityDto);
			sysAuthoritysList.addAll(sysAuthoritys);
		}

		//对所有菜单进行去重
		Set<SysRoleAuthority> set = new TreeSet<SysRoleAuthority>(new Comparator<SysRoleAuthority>() {
			@Override
			public int compare(SysRoleAuthority o1, SysRoleAuthority o2) {
				//字符串,则按照asicc码升序排列
				return o1.getAuthorityId().compareTo(o2.getAuthorityId());
			}
		});
		set.addAll(sysAuthoritysList);
		List<SysRoleAuthority> lastdataList = new ArrayList<SysRoleAuthority>(set);

		if(lastdataList != null && lastdataList.size() > 0) {
			baseResultModel.setData(lastdataList);
			baseResultModel.setStatus(ResultStatus.SUCCESS.getStatusCode());
			baseResultModel.setMessage(ResultStatus.SUCCESS.getStatusMessage());
			return baseResultModel;
		}else {
			baseResultModel.setStatus(ResultStatus.HTTP_REQUEST_ERROR.getStatusCode());
			baseResultModel.setMessage(ResultStatus.HTTP_REQUEST_ERROR.getStatusMessage());
			return baseResultModel;
		}
	}

	/**
	 * @description: 获取公司下的全部的角色用于页面下拉框，无需分页
	 *
	 * @param dto
	 * @return
	 * @author ZhangHao
	 * @date 2018年5月22日 下午6:49:07
	 * @version 1.0.0.1
	 */
	@Override
	public Object ajaxRoleList(SysRoleDto dto) {

		BaseResultModel baseResultModel = new BaseResultModel();

		//获取用户所绑定的参数
		ShiroSessionData shiroSessionData = ShiroSessionDataUtil.getShiroSessionData();
		Long cid = shiroSessionData.getCid();
		dto.setCid(cid);
		dto.setShiroSessionData(shiroSessionData);
		dto.setProductId(0l);
		List<SysRole> sysRoles = roleRpcService.findListByDto(dto);
		if(sysRoles != null && sysRoles.size() > 0) {
			baseResultModel.setData(sysRoles);
			baseResultModel.setStatus(ResultStatus.SUCCESS.getStatusCode());
			baseResultModel.setMessage(ResultStatus.SUCCESS.getStatusMessage());
		}else {
			baseResultModel.setStatus(ResultStatus.HTTP_REQUEST_ERROR.getStatusCode());
			baseResultModel.setMessage(ResultStatus.HTTP_REQUEST_ERROR.getStatusMessage());
		}
		return baseResultModel;
	}

	/**
	 * @description: 根据角色id查询角色对应的一组菜单，无需分页
	 *
	 * @return
	 * @author ZhangHao
	 * @date 2018年5月22日 下午9:46:18
	 * @version 1.0.0.1
	 */
	@Override
	public Object ajaxSelectRoleAuthority(SysRoleAuthorityDto dto) {

		BaseResultModel baseResultModel = new BaseResultModel();
		//获取用户所绑定的参数
		ShiroSessionData shiroSessionData = ShiroSessionDataUtil.getShiroSessionData();
		dto.setShiroSessionData(shiroSessionData);
		dto.setIsDeleted(0);
		List<SysRoleAuthority> SysRoleAuthoritys = roleRpcService.findSysRoleAuthorityByDto(dto);

		if(SysRoleAuthoritys != null && SysRoleAuthoritys.size() > 0) {
			baseResultModel.setData(SysRoleAuthoritys);
			baseResultModel.setStatus(ResultStatus.SUCCESS.getStatusCode());
			baseResultModel.setMessage(ResultStatus.SUCCESS.getStatusMessage());
		}else {
			baseResultModel.setStatus(ResultStatus.HTTP_REQUEST_ERROR.getStatusCode());
			baseResultModel.setMessage(ResultStatus.HTTP_REQUEST_ERROR.getStatusMessage());
		}
		return baseResultModel;
	}

	/**
	 * @description: 检查角色名称是否重复，规则是否正确
	 *
	 * @param dto
	 * @return
	 * @author ZhangHao
	 * @date 2018年5月23日 下午4:39:11
	 * @version 1.0.0.1
	 */
	@Override
	public Object ajaxCheckName(SysRoleDto dto) {

		BaseResultModel baseResultModel = new BaseResultModel();
		//获取用户所绑定的参数
		ShiroSessionData shiroSessionData = ShiroSessionDataUtil.getShiroSessionData();
		dto.setShiroSessionData(shiroSessionData);
		dto.setCid(shiroSessionData.getCid());

		/** 原逻辑迁移 */
		//名字判断
		String newName = dto.getName();

		//规则验证
		Pattern chinaP = Pattern.compile("[\\p{P}&&]+");
		Matcher chinaM = chinaP.matcher(newName);
		boolean chinaKey = chinaM.matches();
		if(chinaKey){
			baseResultModel.setStatus(ResultStatus.HTTP_REQUEST_ERROR.getStatusCode());
			baseResultModel.setMessage("角色名不能全是符号");
			return baseResultModel;
		}
		String[] fhArr = new String[]{"!","@","~","#","$","%","^","&","*","(",")","_","+","-","/","","{","}",":","<",">","?",".","！","￥","……"
				,"（","）","——","=","【","】","[","]","：","；",";","‘","’","“","”","《","》","，",",","。","？","|","\\","、"};
		for (String str : fhArr) {
			newName = newName.replace(str, "");
		}

		if(newName.trim().length() == 0){
			baseResultModel.setStatus(ResultStatus.HTTP_REQUEST_ERROR.getStatusCode());
			baseResultModel.setMessage("角色名不能全是符号");
			return baseResultModel;
		}
		SysRoleDto sysRoleDtoPrm = new SysRoleDto();
		sysRoleDtoPrm.setId(dto.getId());
		sysRoleDtoPrm.setCid(dto.getCid());
		sysRoleDtoPrm.setName(dto.getName());
		//传了id说明是编辑
		if(dto.getId() != null) {
			sysRoleDtoPrm.setId(null);
		}

		SysRole sysRole = roleRpcService.selectSysRoleByType(sysRoleDtoPrm);
		//如果没有该角色，或者查询到的角色id与编辑id相同，那么返回成功
		if(sysRole == null || (dto.getId() != null && dto.getId().equals(sysRole.getId()))) {
			baseResultModel.setStatus(ResultStatus.SUCCESS.getStatusCode());
			baseResultModel.setMessage(ResultStatus.SUCCESS.getStatusMessage());
		}else {
			baseResultModel.setMessage("该角色名称已存在");
		}

		return baseResultModel;
	}

	/**
	 * @description: 新增角色，角色权限，角色外部应用，角色数据权限操作
	 *
	 * @param dto
	 * @return
	 * @author ZhangHao
	 * @date 2018年5月23日 下午5:33:07
	 * @version 1.0.0.1
	 */
	@Override
	public Object create(SysRoleDto dto) {
		BaseResultModel baseResultModel = new BaseResultModel();
		//获取用户所绑定的参数
		ShiroSessionData shiroSessionData = ShiroSessionDataUtil.getShiroSessionData();

		SysRole sysRole = new SysRole();
		//1、根据角色名称、cid、角色描述，角色外部应用，创建一条角色数据，并返回自增id
		sysRole.setName(dto.getName());
		sysRole.setCid(shiroSessionData.getCid());
		sysRole.setExternalAuthority(dto.getExternalAuthority());
		sysRole.setDescription(dto.getDescription());
		sysRole.setCreateUserId(shiroSessionData.getUserId());
		sysRole.setProductId(0l);
		sysRole = roleRpcService.insertSelective(sysRole);
		//2、根据角色id，创建角色对应的数据权限
		String authoritIdList = dto.getAuthoritIdList();
		String[] authoritIdListArr = authoritIdList.split(",");
		//成功标记
		Integer sa = 0;
		for(int i=0;i<authoritIdListArr.length;i++) {
			SysRoleAuthority sysRoleAuthority = new SysRoleAuthority();
			sysRoleAuthority.setRoleId(sysRole.getId());
			String idNameStr = authoritIdListArr[i];
			String[] idNameArr = idNameStr.split("&");
			sysRoleAuthority.setAuthorityId(Long.valueOf(idNameArr[0]));
			sysRoleAuthority.setAuthorityName(idNameArr[1]);
			sa += roleRpcService.insertSysRoleAuthority(sysRoleAuthority);
		}
		//3、根据角色id，创建角色对应的数据权限
		String roleAttribute = dto.getRoleAttribute();
		String[] roleAttributeArr = roleAttribute.split(",");
		Integer sar = 0;
		for(int i=0;i<roleAttributeArr.length;i++) {
			SysAttributeDto sysAttributeDto = new SysAttributeDto();
			sysAttributeDto.setCid(shiroSessionData.getCid());
			sysAttributeDto.setAttributeName(roleAttributeArr[i]);
			SysAttribute sysAttribute = roleRpcService.findSysAttributeByType(sysAttributeDto);
			SysRoleAttribute sysRoleAttribute = new SysRoleAttribute();
			sysRoleAttribute.setAttributeId(sysAttribute.getId());
			sysRoleAttribute.setRoleId(sysRole.getId());
			sysRoleAttribute.setCid(shiroSessionData.getCid());
			sar += roleRpcService.insertSysRoleAttribute(sysRoleAttribute);
		}

		if(sysRole != null && sa > 0 && sar > 0) {
			baseResultModel.setStatus(ResultStatus.SUCCESS.getStatusCode());
			baseResultModel.setMessage(ResultStatus.SUCCESS.getStatusMessage());
		}else {
			baseResultModel.setStatus(ResultStatus.HTTP_REQUEST_ERROR.getStatusCode());
			baseResultModel.setMessage(ResultStatus.HTTP_REQUEST_ERROR.getStatusMessage());
		}
		return baseResultModel;
	}

	/**
	 * @description: 更新角色，角色权限，角色外部应用，角色数据权限操作
	 *
	 * @param dto
	 * @return
	 * @author ZhangHao
	 * @date 2018年5月23日 下午8:08:19
	 * @version 1.0.0.1
	 */
	@Override
	public Object update(final SysRoleDto dto) {
		BaseResultModel baseResultModel = new BaseResultModel();
		//获取用户所绑定的参数
		final ShiroSessionData shiroSessionData = ShiroSessionDataUtil.getShiroSessionData();

		//起一个线程，用于角色更新操作异步执行，提升响应效率
		Runnable myRunnable = new Runnable() {
			public void run() {

				//1、根据角色id，角色名称、cid、角色描述，角色外部应用，更新一条角色数据
				SysRole sysRole = new SysRole();
				sysRole.setName(dto.getName());
				sysRole.setCid(shiroSessionData.getCid());
				sysRole.setId(dto.getId());
				sysRole.setExternalAuthority(dto.getExternalAuthority());
				sysRole.setDescription(dto.getDescription());
				sysRole.setCreateUserId(shiroSessionData.getUserId());
				sysRole.setUpdateTime(new Date());
				roleRpcService.updateSelective(sysRole);

				//2、根据角色id，更新角色对应的菜单权限
				//步骤1：根据角色id把所有角色对应的菜单权限置为is_deleted = 1
				//步骤2：根据角色id，菜单id，从数据库查询是否有该菜单，如果有，根据角色id、菜单id更新对应的is_deleted为 0。如果没有，新增一条is_deleted为0的菜单
				SysRoleAuthorityDto sysRoleAuthorityDto = new SysRoleAuthorityDto();
				sysRoleAuthorityDto.setRoleId(dto.getId());
				sysRoleAuthorityDto.setIsDeleted(1);
				sysRoleAuthorityDto.setUpdateTime(new Date());
				roleRpcService.updateSysRoleAuthorityByDto(sysRoleAuthorityDto);

				String authoritIdList = dto.getAuthoritIdList();
				String[] authoritIdListArr = authoritIdList.split(",");
				//成功标记
				for(int i=0;i<authoritIdListArr.length;i++) {
					//以下逻辑用于更新
					sysRoleAuthorityDto.setRoleId(sysRole.getId());
					String idNameStr = authoritIdListArr[i];
					String[] idNameArr = idNameStr.split("&");
					sysRoleAuthorityDto.setAuthorityId(Long.valueOf(idNameArr[0]));
					sysRoleAuthorityDto.setAuthorityName(idNameArr[1]);
					sysRoleAuthorityDto.setUpdateTime(new Date());
					sysRoleAuthorityDto.setIsDeleted(0);

					//以下逻辑用于插入
					SysRoleAuthority insertEntity = new SysRoleAuthority();
					insertEntity.setRoleId(sysRole.getId());
					insertEntity.setAuthorityId(Long.valueOf(idNameArr[0]));
					insertEntity.setAuthorityName(idNameArr[1]);
					insertEntity.setAuthorityName(idNameArr[1]);

					//查询是否有该菜单，如果没有插入，如果有，进行更新
					SysRoleAuthority resultEntity = roleRpcService.findSysRoleAuthorityByType(sysRoleAuthorityDto);
					if(resultEntity == null) {
						roleRpcService.insertSysRoleAuthority(insertEntity);
					}else {
						roleRpcService.updateSysRoleAuthorityByDto(sysRoleAuthorityDto);
					}
				}

				//3、根据角色id，更新角色对应的数据权限
				//步骤1：根据角色id把所有角色对应的数据权限置为is_deleted = 1
				//步骤2：根据角色id，数据权限id，从数据库查询是否有该盖全，如果有，根据角色id、数据id更新对应的is_deleted为 0.如果没有，新增一条is_deleted为0的数据
				SysRoleAttribute sysRoleAttribute = new SysRoleAttribute();
				sysRoleAttribute.setRoleId(dto.getId());
				sysRoleAttribute.setIsDeleted(1);
				sysRoleAttribute.setUpdateTime(new Date());
				roleRpcService.updateSysRoleAttribute(sysRoleAttribute);

				String roleAttribute = dto.getRoleAttribute();
				String[] roleAttributeArr = roleAttribute.split(",");
				for(int i=0;i<roleAttributeArr.length;i++) {
					SysAttributeDto sysAttributeDto = new SysAttributeDto();
					sysAttributeDto.setCid(shiroSessionData.getCid());
					sysAttributeDto.setAttributeName(roleAttributeArr[i]);
					SysAttribute sysAttribute = roleRpcService.findSysAttributeByType(sysAttributeDto);
					//以下逻辑用于插入、更新
					sysRoleAttribute.setAttributeId(sysAttribute.getId());
					sysRoleAttribute.setRoleId(sysRole.getId());
					sysRoleAttribute.setIsDeleted(0);
					sysRoleAttribute.setUpdateTime(new Date());
					sysRoleAttribute.setCid(shiroSessionData.getCid());

					//以下dto用于定位一条角色数据权限
					SysRoleAttributeDto sysRoleAttributeDto = new SysRoleAttributeDto();
					sysRoleAttributeDto.setAttributeId(sysAttribute.getId());
					sysRoleAttributeDto.setRoleId(sysRole.getId());

					//查询是否有有该数据权限，如果没有插入，如果有，进行更新。
					SysRoleAttribute resultEntity = roleRpcService.findSysRoleAttributeByType(sysRoleAttributeDto);
					if(resultEntity == null) {
						roleRpcService.insertSysRoleAttribute(sysRoleAttribute);
					}else {
						roleRpcService.updateSysRoleAttribute(sysRoleAttribute);
					}
				}
				//获取角色下对应的一批员工id
				SysUserRoleDto sysUserRoleDto = new SysUserRoleDto();
				sysUserRoleDto.setRoleId(dto.getId());
				List<SysUserRole> sysUserRoles = accountRpcService.selectSysUserRoles(sysUserRoleDto);
				if(sysUserRoles != null && sysUserRoles.size() > 0) {
					String userIds = "";
					String roleIds = "";
					for(int i=0;i<sysUserRoles.size();i++) {
						if(i == 0) {
							userIds += sysUserRoles.get(i).getUserId() + "";
						}else {
							userIds += "," + sysUserRoles.get(i).getUserId();
						}
					}
					roleIds = dto.getId() + "";
					SysUserDto sud = new SysUserDto();
					sud.setUserIds(userIds);
					sud.setRoleIds(roleIds);
					sud.setCid(shiroSessionData.getCid());
					//重新赋予CRM权限
					accountService.ajaxCreateUserRolesGroupForCrm(sud);
				}
			}
		};
		Thread thread = new Thread(myRunnable);
		thread.start();
		//返回状态
		try {
			baseResultModel.setStatus(ResultStatus.SUCCESS.getStatusCode());
			baseResultModel.setMessage(ResultStatus.SUCCESS.getStatusMessage());
		} catch (Exception e) {
			e.printStackTrace();
			baseResultModel.setStatus(ResultStatus.HTTP_REQUEST_ERROR.getStatusCode());
			baseResultModel.setMessage(ResultStatus.HTTP_REQUEST_ERROR.getStatusMessage());
		}
		return baseResultModel;
	}

	/**
	 * @description:  从数据库查询全部的菜单权限，为账号开通提供使用
	 *
	 * @param
	 * @author ZhangHao
	 * @date 2018/10/23 13:51
	 * @version 1.0.0.1
	 * @return java.lang.Object
	 */

	@Override
	public Object ajaxAuthorityAll(SysRoleDto dto) {

		BaseResultModel baseResultModel = new BaseResultModel();

		SysAuthorityDto sysAuthorityDto = new SysAuthorityDto();
		List<ShiroSysAuthorityBean> list = accountRpcService.findMenuListByDto(sysAuthorityDto);
		List<SysRoleAuthority> lastdataList = new ArrayList<SysRoleAuthority>();
		for(ShiroSysAuthorityBean entity: list){
			if(!entity.getProductId().equals(1l)) {
				SysRoleAuthority sra = new SysRoleAuthority();
				sra.setAuthorityId(entity.getId());
				sra.setAuthorityParentCode(entity.getParentCode());
				sra.setAuthorityName(entity.getName());
				lastdataList.add(sra);
			}
		}

		if(lastdataList != null && lastdataList.size() > 0) {
			baseResultModel.setData(lastdataList);
			baseResultModel.setStatus(ResultStatus.SUCCESS.getStatusCode());
			baseResultModel.setMessage(ResultStatus.SUCCESS.getStatusMessage());
			return baseResultModel;
		}else {
			baseResultModel.setStatus(ResultStatus.HTTP_REQUEST_ERROR.getStatusCode());
			baseResultModel.setMessage(ResultStatus.HTTP_REQUEST_ERROR.getStatusMessage());
			return baseResultModel;
		}

	}

}
